package com.lagou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * @Authther: mrwu
 * @date:2021/3/24-03
 * @Description:com.lagou.controller
 */
@RequestMapping("/upload")
@Controller
public class UploadController {


    @RequestMapping("/onefile")//但文件上传
    public String upload(MultipartFile uploaddFile, HttpServletRequest request) throws Exception{
         //获取文件夹路径
        String realPath = request.getServletContext().getRealPath("/uplaods");
        //获取文件名
        String originalFilename = uploaddFile.getOriginalFilename();
        //拼接文件存储路径
        String filepath  =realPath+originalFilename+".txt";

        File file = new File(filepath);

        uploaddFile.transferTo(file);//将上传的文件写入文件
        return "sucess";
    }
    //多文件上传
    @RequestMapping("/multifile")
    public String uploadmore(MultipartFile[] fils,HttpServletRequest request){
        //遍历文件对象数组 单个存储
        for (MultipartFile fil : fils) {

        }

        return "sucess";
    }




}
